/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Lending;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

/**
 *
 * @author daz
 */
public class LendingDao extends SimpleJdbcDaoSupport {
    
    public void insertNewLending(Lending lending) {
        String query = "INSERT INTO  bklib.lending "
                + "(USER_ID,BOOK_ID,LENDING_DATE,RETURN_DATE,IS_RETURN) VALUES "
                + "(" + lending.getUserId() + "," + lending.getBookId() + ",'" + lending.getLendingDate() + "','" + lending.getReturnDate() + "'," + lending.getIsReturn() + ");";
        getJdbcTemplate().execute(query);
    }
//    
//    public List<Book> searchBook(String key, String option) {
//        String query = "";
//        if (option.equals("0")) {
//            query = "SELECT * FROM bklib.book b where publisher like '%" + key + "%'";
//        } else if (option.equals("1")) {
//            query = "SELECT * FROM bklib.book b where author like '%" + key + "%'";
//        } else {
//            query = "SELECT * FROM bklib.book b where title like '%" + key + "%'";
//        }
//        return getSimpleJdbcTemplate().query(query, new BookMapper());
//    }
//    
//    private static class LendingMapper implements ParameterizedRowMapper<Lending> {
//        
//        public Lending mapRow(ResultSet rs, int rowNum) throws SQLException {
//            Book book = new Book();
//            book.setAuthor(rs.getString("author"));
//            book.setPublisher(rs.getString("publisher"));
//            book.setTitle(rs.getString("title"));
//            book.setYear(rs.getString("year"));
//            book.setCode(rs.getString("code"));
//            book.setId(rs.getInt("id"));
//            return book;
//        }
//    }
}
